package com.sun.aidldemo

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.os.UserManager
import com.sun.aidlmode.User

class UserService : Service() {

    private  val userList = mutableListOf<User>()
    private  var id = 0;

    fun addUser(name:String,age:Int){
        val  user = User(id++,name,age)
        userList.add(user)
    }
    override fun onCreate() {
        super.onCreate()
        addUser("A",10)
        addUser("B",11)
        addUser("小明",20)


    }
    private  val userManager = object : com.sun.aidlmode.UserManager.Stub(){
        override fun getAllUsers(): MutableList<User> = userList

        override fun addUser(name: String?, age: Int) {
            name?.let {
                this@UserService.addUser(name,age)
            }
        }


    }
    override fun onBind(intent: Intent): IBinder = userManager
}
